﻿#include "project_overview_widget.h"
#include "ui_project_overview_widget.h"
#include "project_info_table.h"

ProjectOverviewWidget::ProjectOverviewWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ProjectOverviewWidget)
{
    ui->setupUi(this);
    initUi();
    initEvents();
}

ProjectOverviewWidget::~ProjectOverviewWidget()
{
    delete ui;
}

void ProjectOverviewWidget::setPrjUuid(QString uuid)
{
    m_projectUuid = uuid;
    setProjectAbstract(uuid);
}

QString ProjectOverviewWidget::getPrjUuid()
{
    return m_projectUuid;
}

void ProjectOverviewWidget::initUi()
{
    setAttribute(Qt::WA_StyledBackground);
}

void ProjectOverviewWidget::initEvents()
{
    connect(ui->projectAbstractWidget, &TextCardWidget::saveBtnClicked, this, [=]() {
        ProjectInfoTable pit;
        pit.updateProjectDescription(m_projectUuid, ui->projectAbstractWidget->getText());
    });
}

void ProjectOverviewWidget::setProjectAbstract(const QString &prjUuid)
{
    ProjectInfoTable pit;
    QString description;
    pit.getProjectDescription(prjUuid, description);
    ui->projectAbstractWidget->setTitle(QStringLiteral("项目描述"));
    ui->projectAbstractWidget->setText(description);
}
